<template>
	<view>
		<z-nav-bar>{{title}}</z-nav-bar>
		<!--<public-module></public-module>-->
		<view class="notice-box">
			<uni-notice-bar single :text="tips"></uni-notice-bar>
		</view>
		<uni-forms :value="formData" ref="form">
			<view class="swiper">
				<view class="forms">
					<view class="title-bar">联系人信息</view>
					<uni-forms-item label="姓名" name="urgentName">
						<uni-easyinput type="text" v-model="formData.urgentName" placeholder="请输入" />
					</uni-forms-item>
					<uni-forms-item label="关系" name="urgentType">
						<vvSelect v-model="formData.urgentType" placeholder="请选择" :list="relationTypeOptions" 
						valueKey="dictValue" label="dictLabel"></vvSelect>
					</uni-forms-item>
					<uni-forms-item label="手机号" name="cellNo">
						<uni-easyinput type="text" v-model="formData.cellNo" placeholder="请输入" />
					</uni-forms-item>
				</view>
			</view>
		</uni-forms>
		<button type="primary" class="btn" @click="submitForm">确定</button>

	</view>
	</view>
</template>

<script>
	import vvSelect from '@/components/vv-select/vv-select'
	export default {
		components: {
			vvSelect
		},
		data() {
			return {
				type: '添加',
				tips: '请填写您的家人、朋友联系方式',
				formData: {
					urgentName: '',
					cellNo: '',
					urgentType: ''
				},
				oldFormData: [],
				relationTypeOptions: [], // 类别list
			}
		},
		onLoad(option) {
			const type = option.type
			if(option.data && option.data !== "undefined") {
				const data = JSON.parse(decodeURIComponent(option.data));
				this.formData = data
				this.oldFormData = data
			}
			
			if (type === 'edit') {
				this.type = '编辑'
			} else if (type === 'add') {
				this.type = '添加'
			}
			
			this.$api.common.getDict("edu_urgent_type").then(res => {
				this.relationTypeOptions = res.data
			})
		},
		computed: {
			title() {
				return this.type + '紧急联系人'
			}
		},
		methods: {
			submitForm() {
				this.$refs.form.submit().then(res => {
					let pages = getCurrentPages();  //获取所有页面栈实例列表
					//let nowPage = pages[ pages.length - 1];  //当前页页面实例
					let prevPage = pages[ pages.length - 2 ];  //上一页页面实例
					
					prevPage.$vm.type = this.type
					prevPage.$vm.tmpUrgent = res
					
					uni.navigateBack({
						delta: 1
					})
				})
				
			}
		},

	}
</script>

<style lang="scss">
	@import '@/style/mixin.scss';

	page {
		background-color: $uni-bg-color-grey;
	}

	.forms {
		width: 686upx;
		margin: 0 auto;
		padding: 24px 16px;
		background: #FEFFFF;
		border-radius: 16px;

		/deep/ input {
			text-align: right;
			outline: none;
		}

		/deep/ .is-input-border {
			border: 0 !important;
		}

		/deep/ .uni-forms-item__label {
			width: 75px !important;
		}

		// 三级选择器
		/deep/ .vv-input__body {
			text-align: right;
			font-size: 14px;
		}

		/deep/ .vv-input__placeholder {
			color: #777;
			font-size: 14px;
		}

		.radio-group {
			text-align: right;
		}

		.title-bar {
			font-size: 17px;
			font-weight: bold;
			color: #323232;
			width: 100%;
			padding-bottom: 10px;
			border-bottom: 1px solid #F5F5F5;
		}

		.select {
			width: 100%;
			text-align: right;
			line-height: 72upx;
		}
	}

	.btn {
		background-color: $uni-theme-color;
		border-radius: 30px;
		margin-top: 36upx;
	}
</style>
